﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LandandSurvey
{
    public partial class AddUser : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            
        }

        protected void btnSave_Click( object sender, EventArgs e )
        {
            using ( landsdbEntities context = new landsdbEntities() )
            {
                AppUser user = new AppUser();

                user.UserName = txtUsername.Text;
                user.Password = txtPassword.Text;
                user.UploadFiles = chkUpload.Checked;
                user.EditAbout = chkEdit.Checked;
                user.IsAdmin = chkAdmin.Checked;

                context.AppUsers.AddObject( user );

                try
                {
                    context.SaveChanges();
                    Response.Redirect( "ViewUsers.aspx" );
                }
                catch
                {
                    lblMessage.InnerText = "An error occured while saving the user record.";
                }
            }
        }
    }
}